package com.xkcun.crm.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xkcun.crm.entity.Channel;
import com.xkcun.crm.param.ChannelListParam;
import com.xkcun.crm.service.ChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 渠道表(Channel)表控制层
 *
 * @author yfz
 * @since 2021-08-06 18:20:30
 */
@Api(value = "", description = "")
@RestController
@RequestMapping("channel")
public class ChannelApi extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private ChannelService channelService;


    @ApiOperation(value = "分页查询", notes = "分页查询")
    @PostMapping("/page")
    public R page(ChannelListParam param) {
        Page<Channel> page = new Page(param.getPageIndex(), param.getPageSize());
        Channel channel = new Channel();
        BeanUtils.copyProperties(param, channel);
        return success(this.channelService.page(page, new QueryWrapper<>(channel)));
    }

    @ApiOperation(value = "获取所有数据", notes = "获取所有数据")
    @PostMapping("/selectAll")
    public R selectAll() {
        return success(this.channelService.list());
    }

    @ApiOperation(value = "详情查询", notes = "详情查询")
    @GetMapping("{id}")
    public R detail(@PathVariable Integer id) {
        return success(this.channelService.getById(id));
    }

    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/save")
    public R insert(@RequestBody Channel channel) {
        return success(this.channelService.save(channel));
    }

    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping("/update")
    public R update(@RequestBody Channel channel) {
        return success(this.channelService.updateById(channel));
    }

    @ApiOperation(value = "删除", notes = "删除")
    @GetMapping("/del/{id}")
    public R delete(@PathVariable Integer id) {
        return success(this.channelService.removeById(id));
    }
}